package com.rownext.kernel.logging.impl 
{
	import com.rownext.kernel.logging.IAppender;
	import com.rownext.kernel.logging.ILogger;
	import com.rownext.kernel.logging.LogLevel;	

	/**
	 * Appender对象的抽象基类
	 * @author Wang Kang
	 */
	public class AbstractAppender implements IAppender
	{
		/**
		 * 构造函数
		 * @param threshold 是否输出日志的阈值级别
		 */
		public function AbstractAppender( threshold:LogLevel = LogLevel.TRACE )
		{
			_threshold = threshold; 
		}

		/**
		 * 为指定的ILogger注册的侦听器
		 */
		public function registerLogger(logger:ILogger):void
		{
			logger.addEventListener(LogEvent.LOG, onLog);
		}

		/**
		 * 是否输出日志的阈值级别
		 */
		public function get threshold():LogLevel
		{
			return _threshold;
		}

		public function set threshold(level:LogLevel):void
		{
			threshold = level;
		}

		/**
		 * <code>LogEvent.LOG</code>事件的侦听器，通过子类重载提供实现。
		 */
		protected function onLog(event:LogEvent):void
		{
		}

		/**
		 * 判断指定的级别是否低于阈值的级别，低于阈值则忽略<code>LogEvent.LOG</code>侦听器动作
		 */
		protected function isBelowThreshold(level:LogLevel):Boolean
		{
			return ( level.value < _threshold.value );
		}

		private var _threshold:LogLevel;
	}
}
